#include <iostream>
#include <unistd.h>
#include <cstdio>
#include "Comm.hpp"

int main()
{
    char buffer[1024];
    SetNonBlock(0);

    while(true)
    {
        // printf("Enter# ");
        // fflush(stdout);
        ssize_t n = ::read(0, buffer, sizeof(buffer) - 1);
        if(n > 0)
        {
            buffer[n] = 0;
            printf("echo# %s", buffer);
        }
        else if(n == 0) // read done
        {
            printf("read done\n");
            break;
        }
        else
        {
            if(errno == EWOULDBLOCK)
            {
                sleep(1);
                std::cout << "底层数据没有就绪，开始轮询检测" << std::endl;
                // do other
                continue;
            }
            else if(errno == EINTR)
            {
                continue;
            }
            else
            {
                perror("read\n");
                break;
            }
        }
    }
}